package com.pro.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.pro.dao.impl.NewsDaoImpl;
import com.pro.dao.impl.NewsTypeDaoImpl;
import com.pro.util.BaseServlet;

/**
 * Servlet implementation class NewsServlet
 */
public class NewsServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;
       NewsDaoImpl newDaoImpl = new NewsDaoImpl();
       NewsTypeDaoImpl nTypeDaoImpl = new NewsTypeDaoImpl();
       
	public void newsAll(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
		int nid=Integer.parseInt(request.getParameter("nid"));
		//新闻资讯详情
				request.setAttribute("newsList", newDaoImpl.newsAll(nid));
				request.setAttribute("newsTypeList", nTypeDaoImpl.newsType());
				
				request.getRequestDispatcher("article_list.jsp").forward(request, response);
			}
			
			public void newsDetail(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
				int id=Integer.parseInt(request.getParameter("id"));
				//新闻资讯详情
				request.setAttribute("news", newDaoImpl.newsDetail(id));
				request.setAttribute("newsTypeList", nTypeDaoImpl.newsType());
				//找出 距离这个id的上一个和下一个
				request.setAttribute("newsPre", newDaoImpl.newsPreAndNext(id,0));
				request.setAttribute("newsNext", newDaoImpl.newsPreAndNext(id,1));
				request.getRequestDispatcher("article_list_content.jsp").forward(request, response);
			}

		}
